package task_process

import (
	"context"
	"fmt"
	"github.com/gogf/gf/frame/g"
	"github.com/hibiken/asynq"
	"grabcad_spider/grabcad"
)

func ProcessGetList(url string) {

	list, err := grabcad.GetList(url)
	if err != nil {
		fmt.Println("grabcad列表[处理出错]: "+" url :"+url, err)
	}
	for _, v := range list {
		err := AddDetailTask(v)
		if err != nil {
			fmt.Println("grabcad详情[添加任务失败]: "+" url :"+v, err)
		}
	}
}

func AddDetailTask(url string) error {
	return AddTaskToQueue(GRABCAD_TASK_TYPE_ARTICLE, g.Map{"article_url": url}, 0)
}

func GrabcadProcessArticle(c context.Context, t *asynq.Task) error {
	url, _ := t.Payload.GetString("article_url")

	err := grabcad.GetDetail(url)
	if err != nil {
		fmt.Println("grabcad详情[处理出错]: "+" url :"+url, err)
	}

	return nil
}
